import {
	formatDate
} from '../../../utils/tools.js'

export default {
	data() {
		return {
			sort: {
				code: true,
				model: true,
				outType: true
			}
		}
	},
	computed: {
		listLength() {
			return this.list.length;
		}
	},
	methods: {
		dateColorFormatter(date) {
			if (date) {
				let color = '#606266'
				let time = new Date(date).getTime()
				let time_diff = time - new Date().getTime(); //时间差的毫秒数
				//计算出相差天数
				let days = Math.floor(time_diff / (24 * 3600 * 1000));
				if (days < -180) {
					color = '#19be6b'
				}
				if (days < -365) {
					color = '#fa3534'
				}
				return color
			} else {
				return '#606266'
			}
		},
		formatProductDate(str) {
			if (str) {
				str = str.replace(/\-/g, '/')
				return formatDate(new Date(str), 'yyyy-MM-dd')
			} else {
				return ''
			}
		},
		sortBy(key) {
			let listCache = JSON.parse(JSON.stringify(this.list));
			listCache.sort((a, b) => {
				return this.sort[key] ? a[key] > b[key] ? 1 : -1 : b[key] > a[key] ? 1 : -1;
			});
			this.sort[key] = !this.sort[key];
			// this.list = listCache;
			this.$emit('sort-change', listCache)
		},
	}
}
